{extend name='public/base' /}
{block name='content'}
{include file='public/content_header' /}
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <!-- 表单头部 -->
                <div class="card-header">
                    <div class="btn-group">
                        <a class="btn flat btn-sm btn-default BackButton">
                            <i class="fas fa-arrow-left"></i>
                            返回
                        </a>
                    </div>
                </div>
                <!-- 表单 -->
                <form id="dataForm" class="form-horizontal dataForm" action="" method="post" enctype="multipart/form-data">
                    <!-- 表单字段区域 -->
                    <div class="card-body">
                        <div class="form-group row rowSelect">
    <label for="parent_id" class="col-sm-2 col-form-label">商品分类</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
        <select name="parent_id" id="parent_id" class="form-control select2bs4 fieldSelect" data-placeholder="请选择商品分类">
            <option value=""></option>
            {foreach name='parent_list' id='item'}
    <option value="{$item.id}" {if isset($data) && $data.parent_id==$item.id}selected{/if}>
        {$item.name}
    </option>
{/foreach}
        </select>
    </div>

    <script>
        $('#parent_id').select2({
            theme: 'bootstrap4'
        });
    </script>
</div>
<div class="form-group row rowSelect">
    <label for="type_id" class="col-sm-2 col-form-label">商品</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
        <select name="type_id" id="type_id" class="form-control select2bs4 fieldSelect" data-placeholder="请选择商品">
            <option value=""></option>
            {foreach name='type_list' id='item'}
    <option value="{$item.id}" {if isset($data) && $data.type_id==$item.id}selected{/if}>
        {$item.name}
    </option>
{/foreach}
        </select>
    </div>

    <script>
        $('#type_id').select2({
            theme: 'bootstrap4'
        });
    </script>
</div>
<div class="form-group row rowSelect">
    <label for="spec_id" class="col-sm-2 col-form-label">规格</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
        <select name="spec_id" id="spec_id" class="form-control select2bs4 fieldSelect" data-placeholder="请选择规格">
            <option value=""></option>
            {foreach name='spec_list' id='item'}
    <option value="{$item.id}" {if isset($data) && $data.spec_id==$item.id}selected{/if}>
        {$item.name}
    </option>
{/foreach}
        </select>
    </div>

    <script>
        $('#spec_id').select2({
            theme: 'bootstrap4'
        });
    </script>
</div>
<div class="form-group row rowSelect">
    <label for="brand_id" class="col-sm-2 col-form-label">单位</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
        <select name="brand_id" id="brand_id" class="form-control select2bs4 fieldSelect" data-placeholder="请选择单位">
            <option value=""></option>
            {foreach name='brand_list' id='item'}
    <option value="{$item.id}" {if isset($data) && $data.brand_id==$item.id}selected{/if}>
        {$item.name}
    </option>
{/foreach}
        </select>
    </div>

    <script>
        $('#brand_id').select2({
            theme: 'bootstrap4'
        });
    </script>
</div>
<div class="form-group row rowText">
    <label for="code" class="col-sm-2 col-form-label">商品编码</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
        <input id="code" name="code" value="{$data.code|default=''}" placeholder="请输入商品编码" type="text" class="form-control fieldText">
    </div>
</div>
<div class="form-group row rowText">
    <label for="all_num" class="col-sm-2 col-form-label">总数量</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
        <input id="all_num" name="all_num" value="{$data.all_num|default='0'}" placeholder="请输入总数量" type="text" class="form-control fieldText">
    </div>
</div>

                    </div>
                    <!-- 表单底部 -->
                    <div class="card-footer">
                        <div class="row">
                            <div class="col-sm-2">
                            </div>

                            <div class="col-sm-10 col-md-4 formInputDiv">

                                <div class="btn-group">
                                    <button type="submit" class="btn btn-sm btn-primary dataFormSubmit">
                                        保 存
                                    </button>
                                </div>
                                <div class="btn-group">
                                    <button type="reset" class="btn btn-sm btn-default dataFormReset">
                                        重 置
                                    </button>
                                </div>

                                {if !isset($data)}
                                <div class="btn-group float-right createContinueDiv">
                                    <input type="checkbox" class="form-check-input" value="1" id="_create" name="_create" title="继续添加数据">
                                    <label class="form-check-label" for="_create">继续添加</label>
                                </div>
                                {/if}
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>
<script>
    /** 表单验证 **/
    $('#dataForm').validate({
        rules: {
                'parent_id': {
                required: true,

    },
    'type_id': {
                required: true,

    },
    'spec_id': {
                required: true,

    },
    'brand_id': {
                required: true,

    },
    'code': {
                required: true,

    },
    'all_num': {
                required: true,

    },

        },
        messages: {
                'parent_id': {
               required: "商品分类不能为空",

    },
    'type_id': {
               required: "商品不能为空",

    },
    'spec_id': {
               required: "规格不能为空",

    },
    'brand_id': {
               required: "单位不能为空",

    },
    'code': {
               required: "商品编码不能为空",

    },
    'all_num': {
               required: "总数量不能为空",

    },

        }
    });
</script>
{/block}